
using System;
using System.Collections.Generic;

namespace cachier
{


	public class CurrencyHandler
	{
		int[] nominals;
		int[] amounts;

		String name;

		public CurrencyHandler (String name, int[] nominals)
		{
			this.nominals = nominals;
			this.name = name;
			
			amounts = new int[nominals.Length];
		}

		public bool Add (int nominal, int value)
		{
			if (nominal <= 0 || value <= 0)
				return false;
			
			int index = Array.BinarySearch (nominals, nominal);
			if (index < 0)
				return false;
			
			amounts[index] += value;
			
			return true;
		}

		bool Get (int nominal, int value)
		{
			if (nominal <= 0 || value <= 0)
				return false;
			
			int index = Array.BinarySearch (nominals, nominal);
			if (index < 0 || amounts[index] < value)
				return false;
			
			amounts[index] -= value;
			
			return true;
		}

		public int ShowAmount (int nominalIndex)
		{
			return amounts[nominalIndex];
		}

		public int ShowNominal (int nominalIndex)
		{
			return nominals[nominalIndex];
		}

		public int GetNominalsLength ()
		{
			return nominals.Length;
		}

		public void Process (Dictionary<int, int> data)
		{
			foreach (KeyValuePair<int, int> pair in data) {
				Get (pair.Key, pair.Value);
				Display.Out (pair.Key + " " + pair.Value + " OK");
			}
		}
	}
}